<?php
namespace app\adminapi\export;

use PhpOffice\PhpSpreadsheet\IOFactory;

class BaseUplod {

    public $fileName = '';


    public function parseData(){
        if($this->fileName == '')
            return [];
        $spreadsheet = IOFactory::load($this->fileName);

        // 获取第一个工作表
        $worksheet = $spreadsheet->getActiveSheet();

        $data = [];
        // 遍历工作表中的行
        foreach ($worksheet->getRowIterator() as $k => $row) {
            $cellIterator = $row->getCellIterator();
            $cellIterator->setIterateOnlyExistingCells(false);
            foreach ($cellIterator as $cell) {
                // 获取单元格的值
                $value = $cell->getValue();
                $data[$k][] = $value;
            }
        }

        return $data;
    }
}